package com.yaojiaxun.logisticsPlatformSystem.mapper;

import com.baomidou.mybatisplus.mapper.BaseMapper;
import com.yaojiaxun.logisticsPlatformSystem.entity.CertificateInfo;
import org.apache.ibatis.annotations.*;
import org.springframework.web.bind.annotation.RequestParam;

/**
 * @Auther: yjx_j
 * @Date: 2019/1/22 10:58
 * @Description:
 */
@Mapper
public interface CertificateInfoMapper extends BaseMapper<CertificateInfo> {

    @Select("select * from certificate_info where certificate_id=#{certificateId} and grant_object='单位'")
    public CertificateInfo findCertificateById(@Param("certificateId") Long certificateId);

    @Delete("delete from certificate_info where certificate_id=#{certificateId}")
    public void deleteCertificateById(@RequestParam("certificateId") Long certificateId);

    @Insert("insert into certificate_info(certificate_id, certificate_name, certificate_type, certificate_num, grant_object, grant_name, review_cycle, " +
            "transact_unit, create_time, update_time) values(#{certificateInfo.certificateId}, #{certificateInfo.certificateName}, #{certificateInfo.certificateType}, " +
            "#{certificateInfo.certificateNum}, #{certificateInfo.grantObject}, #{certificateInfo.grantName}, #{certificateInfo.reviewCycle}, #{certificateInfo.transactUnit}, " +
            "#{certificateInfo.createTime}, #{certificateInfo.updateTime})")
    public Integer addCertificate(@Param("certificateInfo") CertificateInfo certificateInfo);

    @Update("update certificate_info set certificate_name=#{certificateName},certificate_type=#{certificateType}, certificate_num=#{certificateNum}, grant_object=#{grantObject}, " +
            "grant_name=#{grantName}, review_cycle=#{reviewCycle}, transact_unit=#{transactUnit} where certificate_id=#{certificateId}")
    public Integer updateCertificate(@RequestParam("certificateInfo") CertificateInfo certificateInfo);

    @Select("select * from certificate_info where grant_name = #{comName}")
    public CertificateInfo findCertificateByComName(@Param("comName") String comName);
}
